package com.wuba.rxjavademo.tzx.create;

import com.wuba.rxjavademo.tzx.common.Base;

import java.util.concurrent.TimeUnit;

import rx.Observable;

/**
 * Created by tanzhenxing
 * Date: 2016/6/24.
 * Description:
 * interval:在异步线程中轮询发射。interval(long interval, TimeUnit unit)函数的两个参数：一个指定两次发射的时间间隔，另一个是用到的时间单位。
 * 类似于一个计时器
 */
public class RxInterval extends Base {
    public static void main(String[] args) {
        RxInterval interval = new RxInterval();
        Observable<Long> observable = Observable.interval(1,TimeUnit.SECONDS);
        observable.subscribe(subscriber -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        observable.subscribe(num -> {print("---run---" + num);});
        print("11111");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
